﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Controls;
using hStatsC.Helper;
using hStatsC.Models;
using LiveCharts;
using LiveCharts.Wpf;
using Panuon.UI.Silver;
using PropertyChanged;

namespace hStatsC.Views
{
    [AddINotifyPropertyChangedInterface]
    public partial class StatisticView : UserControl
    {
        public AppInfo App { get; set; }

        public int TodayLaunchTimes { get; set; }

        public int TotalLaunchTimes { get; set; }
        public int NowOnline { get; set; }

        public ObservableCollection<AppLaunchTime> Als { get; set; }
        public ObservableCollection<DateTime> AlsDates { get; set; }
        public SeriesCollection AlsCounts { get; set; }


        public StatisticView()
        {
            InitializeComponent();
            DataContext = this;
        }

        private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                TodayLaunchTimes = MainHelper.Today(App.App);
                Als = new ObservableCollection<AppLaunchTime>(MainHelper.AllLaunchTimes(App.App));
                TotalLaunchTimes = Als.Sum(x=>x.Times);
                NowOnline = MainHelper.NowOnline(App.App);
                
                Console.WriteLine(TodayLaunchTimes);
                Console.WriteLine(TotalLaunchTimes);
            }
            catch (Exception exception)
            {
                MessageBoxX.Show($"获取App启动次数相关数据时异常\n{exception.Message}", "异常");
            }
        }


    }
}